package org.rency.crawler.app.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/24 16:11<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/24 16:11
 */
@RestController
@Configuration
@EnableSwagger2
public class SwaggerController {

  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
        .apis(RequestHandlerSelectors.basePackage("org.rency.crawler"))
        .paths(PathSelectors.any()).build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("爬虫服务")
        .description("基于网络文档抓取、数据分析的服务。")
        .termsOfServiceUrl("http://blog.csdn.net/user_rcy")
        .contact(new Contact("rency", "https://gitee.com/rency", "user_rcy@163.com"))
        .version("2.0.0")
        .build();
  }

  @ApiOperation(value = "文档")
  @RequestMapping(value = "/api-docs", method = RequestMethod.GET)
  public ModelAndView api() {
    return new ModelAndView("redirect:/swagger-ui.html");
  }


}
